fix: return zero rates instead of NaN for zero-rate compressor timesteps#1535
Open
fix: return zero rates instead of NaN for zero-rate compressor timesteps#1535
Conversation
220c8fd to
5e9b82d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Work
See here (internal): https://github.com/equinor/ecalc-internal/discussions/1044
Have you remembered and considered?
docs/drafts/next.draft.md)docs/docs/migration_guides/)BREAKING:in footer or!in headerWhat is this PR all about?
When a compressor has zero input rate, the compressor train returns
create_empty()stage results whereinlet_stream = None, and all rate properties (inlet_actual_rate,mass_rate,standard_rate, etc.) returnNaN.During yearly resampling,
TimeSeries.resample()usesffill(). The inputrate_sm3_day = 0survives correctly, but theNaNactual-rate fields get forward-filled with the last positive value — producing a mismatch where standard rate = 0 but inlet actual rate > 0. The bug only manifests with yearly output frequency.This PR changes 8 rate properties in
CompressorTrainStageResultSingleTimeStepto return0.0instead ofnp.nanwhen the stream isNone. Zero flow means zero actual / standard / mass rate — physically correct and resampling-stable. Pressure, density, kappa, z-factor, and temperature still returnNaNat zero flow because those quantities are genuinely undefined.What else did you consider?
Fixing this in the resampling layer instead — but
ffillis the right behaviour for genuinely missing samples; the problem is that the source values were neverNaNin a meaningful sense. Fixing it at the source is cleaner.Between the lines?
test_zero_rate_gives_zero_actual_rate_not_nan(simplified train)np.isnan(...)to== 0.0Resolves equinor/ecalc-internal#1398 (sub-issue of equinor/ecalc-internal#1392).